#ifndef __INITDEF__H
#define __INITDEF__H
#define 	AN0		1			//add by peter,use to exchange AN0 and AN4

////////////////////////////////////////////////////////////////////////////////
// BSC
#define CSRAM_SIZE_BYTE		0
#define CSRAM_SIZE_WORD		1
#define CSRAM_IW_IDLE_NO	0
#define CSRAM_IW_IDLE_ONE	1
#define CSRAM_IW_IDLE_TWO	2
#define CSRAM_IW_IDLE_THREE	3
#define CSRAM_CW_IDLE_NO	0
#define CSRAM_CW_IDLE_ONE	1
#define CSRAM_SW_NOASSERT	0
#define CSRAM_SW_ASSERT		1

#define CSRAM_BCR2_WORD		0
#define CSRAM_WAIT_CYCLE	1
#define CSRAM_DMA_WAIT		0

////////////////////////////////////////////////////////////////////////////////
// INTC
#define INT_PRIORITY_TIMER	15		// CMT for 1ms timer
#define INT_PRIORITY_SHOT   13      // EXT for Shot timer 
#define INT_PRIORITY_RSS	10		// ATU5 for read switch signal timer
#define INT_PRIORITY_COMM0  5		// SCI for MBOX & RCPC communication
#define INT_PRIORITY_COMM2  6 

////////////////////////////////////////////////////////////////////////////////
// port

// port A is Address Bus
#define PORT_MODE_A			0xffff

// port D is Data Bus
#define PORT_MODE_D			0xffff

// port B
// PB0 , bit  0,	out,	HV-ON-LED
// PB1 , bit  1,	out,	POWER-LED
// PB2 , bit  2,	 in,	input-spare3a
// PB3 , bit  3,	out,	adjust beam(LD)
// PB4 , bit  4,	out,	READY-LED
// PB5 , bit  5,	out,	MAIN-SHUTTER1-LED
// PB6 , bit  8,     ADDRESS16
// PB7 , bit  9,     ADDRESS17
// PB8 , bit 10,	 in,	flow signal
// PB9 , bit 11,	 in,	FLOAT
// PB10, bit 12,	 in,	OVHEAT
// PB11, bit 13,	out,	battery voltage check selection
#define PORT_MODE_B			0x83c0
#define PORT_DIRECTION_B	0xe0fb
#define PORT_INITIALWORD_B	0x203b

// port C
// PC2 , bit  2,	 in,	DIP SW1(3/8)
// PC4 , bit  4,	 in,	reserve
// PC7 , bit  7,	 in,	branch cover switch
// PC8 , bit  8,	 in,	laser cover switch
// PC9 , bit  9,	out,	mirror2-sol
// PC10, bit 10,	out,	mirror1-sol
// PC11, bit 11,	out,	branch shutter 3 switch
// PC12, bit 12,	out,	branch shutter 2 switch
// PC13, bit 13,	out,	branch shutter 1 switch
// PC14, bit 14,	out,	main shutter switch
#define PORT_MODE_C1		0xc000
#define PORT_MODE_C2		0x1eef
#define PORT_DIRECTION_C	0xfe00
#define PORT_INITIALWORD_C	0x7e00

// port E
// PE0 , bit  0,	out,	SHUT4-LED
// PE1 , bit  1,	out,	cooler fan switch
// PE2 , bit  2,	out,	cooler pump switch
// PE3 , bit  3,	out,	discahrge error reset switch
// PE4 , bit  4,	out,	feedback mode switch
// PE5
// PE6 , bit  6,	 in,	charge alarm status
// PE7 , bit  7,	 in,	charge ready status
// PE8 , bit  8,	out,	MAIN-SHUTTER2-LED
// PE9 , bit  9,	out,	SHUTTER1-LED
// PE10, bit 10,	out,	SHUTTER2-LED
// PE11, bit 11,	out,	SHUTTER3-LED
// PE12, bit 12,	out,	charge error reset switch
// PE13, bit 13,	out,	high voltage switch
// PE14, bit 14,	out,	SHUTTER5-LED
#define PORT_MODE_E			0x8020
#define PORT_DIRECTION_E	0xff3f
#define PORT_INITIALWORD_E	0xcf01

// port F
// PF0 , bit  0,	out,	RCPC(SCI0, RS-485) transmit enable
// PF1 , bit  1,	 in,	SHUTTER2-CLOSE status
// PF2 , bit  2,	 in,	SHUTTER1-CLOSE status
// PF3 , bit  3,	out,	SHUTTER6-SOL switch
// PF4 , bit  4,	 in,	ctr-mode-sel1(mbox\rcpc\etex)
// PF5 , bit  5,	out,	MIRROR5-SOL  switch
// PF6 , bit  6,	out,	MIRROR4-SOL  switch
// PF7 , bit  7,	out,	MIRROR3-SOL  switch
// PF8 , bit  8,	out,	MBOX(SCI2, RS-485) transmit enable
// PF9 , bit  9,	 in,	LASER START interrupt IRQ7
// PF10, bit  10,	 in,	DIP SW1(2/8) status
// PF11, bit  11,	 in,	DIP SW1(1/8) status
#define PORT_MODE_F1		0xff08
#define PORT_MODE_F2		0x00aa	
#define PORT_DIRECTION_F	0xf1e9
#define PORT_INITIALWORD_F	0xf0e8

// port G
// PG0 , bit  0,	 in,	LED_DRV -5
// PG1 , bit  1,	out,	LED_DRV -6
// PG2
// PG3
// PG4 , bit  4,	 in,	SHUTTER3-CLOSE status
// PG5
// PG6
// PG7
// PG8
// PG9 , bit  9,	out,	SHUTTER6-LED
// PG10, bit 10,	 in,	simmer1 ready status
// PG11, bit 11,	out,	simmer control switch
// PG12, bit 12,	 in,	power monitor heat
// PG13, bit 13,	 in,	front cover switch status
// PG14, bit 14,	out,	SHUTTER5-SOL switch
// PG15, bit 15,	out,	SHUTTER4-SOL switch
#define PORT_MODE_G1		0x0aab
#define PORT_MODE_G2		0xfee0
#define PORT_DIRECTION_G	0xcbee
#define PORT_INITIALWORD_G	0xc002

// port H
// PH0
// PH1 , bit  1,     in,    battery voltage test
// PH2 , bit  2,     in,    remote-interlock switch status
// PH3 , bit  3,	 in,	emergent stop switch status
// PH4
// PH5 , bit  5,     in,	safety key-switch status
// PH6
// PH7
// PH8
// PH9
// PH10, bit 10,	 in,	over-control1
// PH11, bit 11,	 in,	over-control2
// PH12, bit 12,	 in,	simmer2-ok
// PH13, bit 13,	 in,	bank2-ready
// PH14, bit 14,	 in,	bank2-alarm
// PH15, bit 15,	 in,	ctr-mode-sel2(mbox\rcpc\etex)

////////////////////////////////////////////////////////////////////////////////
// CMT
// CMT 0, 100us timer
#define CMT0_TIMER_INTERVAL	0x0271

////////////////////////////////////////////////////////////////////////////////
// SCI
// SCI 2: Async, 9600bps, 8bit, even parity, 1stop
//#define SCI2_BAUD_RATE		64		//9600	
#define SCI2_BAUD_RATE		32		//19200
#define SCI0_BAUD_RATE		32		//19200

////////////////////////////////////////////////////////////////////////////////
// ADC
// no scan, no trigger, no interrupt, stop conversion, conversion time is 134
// AD0 channel: AN0(PH0), PIN 137, energy
//				AN4(PH4), PIN 141, 10*energy
//				AN6(PH6), PIN 145, CAP2-V
//				AN7(PH7), PIN 146, CAP1-V
//				AN8(PH8), PIN 147, WATER-TEMP
//				AN9(PH9), PIN 148, DEIO
// AD1 channel: 
#define AD0_CONTROL_WORD	0x5f
#if AN0
#define AD0_CRL_STA_WORD	0x01
#else
#define AD0_CRL_STA_WORD	0x04
#endif
#define AD1_CONTROL_WORD	0x7f
#define AD1_CRL_STA_WORD	0x08

////////////////////////////////////////////////////////////////////////////////
// ATU
//     channel  1: control TIOF1 output(FLASH signal)
//     channel  5: timer for read switch signal(only use A - GR5A)
//     channel 10: exact delay when control laser output
//                 A - timer of delayed power monitor
//                 B - timer of common delay purpose
//                 H - timer of FLASH pulse cycle
// first-stage counter clock: 1/10, 2MHz(cycle: 0.1us)
#define ATU_PRESCALER_PSCR1	0x09
#define ATU1_CONTROL_WORD	0x01	// internal clock 1/2, 1MHz(1us),0.1us
#define ATU1_IOCONTROL_WORD	0x00	// compare output, always output 0
#define ATU3_TIMERMODE_WORD	0x00	// disable PWM mode for channel 3, 4, 5
#define ATU5_CONTROL_WORD	0x05	// internal clock 1/32, 62.5kHz(16us)
#define ATU5_IOCONTROL_WORD	0x08	// A(GR5A): TCNT cleared, GR5A compare-match
#define ATU5_INTERVAL_GR5A	 625	// 10ms(625x16us) interval to read switch signal
#define ATU10_CONTROL_WORD	0x15	// A clock 1MHz(1us), B clock 62.5kHz(16us)

////////////////////////////////////////////////////////////////////////////////
// PIO
#define PIO1_CONTROL_CMD	0x9b
#define PIO2_CONTROL_CMD	0x80
#define PIO2_INITIALBYTE_P0	0xff
#define PIO2_INITIALBYTE_P1	0xff
#define PIO2_INITIALBYTE_P2	0xff
#define PIO3_CONTROL_CMD	0x9b


#endif // __INITDEF__H
